package nature.nano.util.accepter;

import java.util.Random;

import nature.nano.iface.Accepter;
import nature.nano.iface.Props;

public class ErrorGenerator implements Accepter {

	private int rate = 5;
	
	public ErrorGenerator() {
	}
	
	public ErrorGenerator(int rate) {
		this.rate = rate;
	}
	
	@Override
	public void onBegin(String type, Props props) {
		random();
	}

	@Override
	public void onContent(String content) {
		random();
	}

	@Override
	public void onEnd(String type) {
		random();
	}

	private void random() {
		Random generator = new Random();
		boolean error = (generator.nextInt() % rate == 0) ? false : true;
		if (error) {
			long a = 100;
			long b = 0;
			a = a / b;
		}
	}

}
